import * as echarts from 'echarts'
import 'echarts/dist/extension/dataTool';
var myChart;
export function boxPlot(data, options){//仪表盘
    // let  data1= JSON.parse(JSON.stringify(data));
    var data = echarts.dataTool.prepareBoxplotData(data);
    var option = {
        dataZoom: options['dataZoom'] || '',
        title: [
            {
                text: '',
                left: 'center',
            },
            // {
            //     text: 'upper: Q3 + 1.5 * IQR \nlower: Q1 - 1.5 * IQR',
            //     borderColor: '#999',
            //     borderWidth: 1,
            //     textStyle: {
            //         fontSize: 14
            //     },
            //     left: '10%',
            //     top: '90%'
            // }
        ],
        tooltip: {
            trigger: 'item',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '6%',
            right: '10%',
            bottom: '15%'
        },
        xAxis: {
            type: 'category',
            data: options['legend'],
            boundaryGap: true,
            nameGap: 30,
            splitArea: {
                show: false
            },
            // axisLabel: {
            //     formatter: '{value+1}班'
            // },
            splitLine: {
                show: false
            }
        },
        yAxis: {
            type: 'value',
            name: options['yAxisName'],
            splitArea: {
                show: true
            },
            nameLocation: 'center',
            nameTextStyle: {
                align: 'center',
                // width: '100%',
                padding: [0, 0, 20, 0]
            }
        },
        series: [
            {
                name: 'boxplot',
                type: 'boxplot',
                data: data.boxData,
                tooltip: {
                    formatter: function (param) {
                        return [
                            ' ' + param.name + ': ',
                            '上限: ' + param.data[5],
                            '上四分位: ' + param.data[4],
                            '中位数: ' + param.data[3],
                            '下四分位: ' + param.data[2],
                            '下限: ' + param.data[1]
                        ].join('<br/>');
                    }
                }
            },
            {
                name: '异常值',
                type: 'scatter',
                data: data.outliers
            }
        ]
    };
    myChart && myChart.dispose();
    myChart = echarts.init(document.getElementById(options['id']));
	myChart.clear();
	myChart.setOption(option);
}
export default boxPlot = boxPlot;

